package com.lhy.example.configruation;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lhy.common.web.java8time.Java8TimeObjectMapperFactory;
import com.lhy.common.web.java8time.StringToLocalDateConverter;
import com.lhy.common.web.java8time.StringToLocalDateTimeConverter;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.convert.converter.Converter;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE)

public class WebMvcConfiguration implements WebMvcRegistrations {

    /**
     * 如果需要精细的权限控制，不要注释该方法，RequestMappingHandlerMapping，
     * 解除注释后需要显示覆盖申明controller方法 并用@SimpleMapping注解标记
     */
//        @Override
//        public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
//            return new SimpleCrudRequestMappingHandlerMapping();
//        }
    @Bean
    public ObjectMapper objectMapper() {
        return Java8TimeObjectMapperFactory.newObjectMapper();
    }

    @Bean("stringToLocalDateConverter")
    public Converter<String, LocalDate> stringToLocalDateConverter() {
        return new StringToLocalDateConverter();
    }

    @Bean("stringToLocalDateTimeConverter")
    public Converter<String, LocalDateTime> stringToLocalDateTimeConverter() {
        return new StringToLocalDateTimeConverter();
    }
}

